#include "StdAfx.h"
#include "SocketStreamInput.h"
#include "IStreamInput.h"
#include "Element.h"
#include "IOManager.h"
#include "JsonSchema.h"
#include <boost/shared_ptr.hpp>
SocketStreamInput::SocketStreamInput(std::string ip,std::string port,boost::shared_ptr<JsonSchema> schema):IStreamInput(schema)
{
	this->ip = ip;
	this->port = port;
}


SocketStreamInput::~SocketStreamInput(void)
{
}
void SocketStreamInput::getNextElement(Element& element)
{

	assert(!isEmpty());
	std::istream is (&streambuffer,std::ios::binary);
	is>>element;

}
bool SocketStreamInput::isEmpty()
{

	return !(this->streambuffer.size()>0);
}
void SocketStreamInput::readData(char* data, int length)
{
	boost::asio::streambuf& streambuffer = this->streambuffer;
	//boost::asio::streambuf streambuffer ;
	std::ostream os(&streambuffer,std::ios::binary);
	os.write(data,length);
}
void SocketStreamInput::initial()
{
	IOManager::getInstance()->addStreamInput(ip,port,this);
}